package com.xio.cloud.controller;

import com.xio.cloud.domain.Account;
import com.xio.cloud.domain.CommonResult;
import com.xio.cloud.service.AccountService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Author: xio
 * @Description: 账户控制器
 * @Date: 2021/3/31 20:56
 */
@RestController
public class AccountController {

    @Resource
    private AccountService accountService;

    @GetMapping("/{id}")
    public Account get(@PathVariable String id) {
        return accountService.getById(id);
    }

    @GetMapping("/account/decrease")
    CommonResult decrease(@RequestParam("userId") Long userId,
                          @RequestParam("money") BigDecimal money) {
        return CommonResult.of(accountService.decrease(userId, money), "减少账户余额成功");
    }

}
